class Solution {
public:
    int maxCount(vector<int>& banned, int n, int maxSum) {
        int hash[10001];
        memset(hash, 0, sizeof(hash));
        for(auto& b : banned)
            ++hash[b];
        
        int i = 1, count = 0;
        for(; i <= n; ++i)
        {
            if(hash[i] == 0)
            {
                int res = maxSum - i;
                if(res < 0)
                {
                    break;
                }
                else
                {
                    maxSum = res;
                    ++count;
                }
            }
        }

        return count;
    }
};
